class Article < ActiveRecord::Base
  belongs_to :documet_type
  belongs_to :author,
    :class_name => "Valleyer",
    :foreign_key => "author_id"
  has_many :post_sessions

  #同分类的日志
  def the_same_documet_type_logs(args = { :last => 8})
    Article.all :conditions => ["documet_type_id = ?", self.documet_type_id],
      :order => "created_at desc",
      :limit => args[:last]
  end

  #不同分类的日志
  def the_diverse_documet_type_logs(args = {:last => 8})
    Article.all :conditions => ["documet_type_id != ?", self.documet_type_id],
      :order => "created_at desc",
      :limit => args[:last]
  end

  #系统中最新的日志
  #根据updated_at
  def self.up_to_date_articles(args = {:last => 3})
    Article.all :order => "updated_at desc",
      :limit => args[:last]
  end

  #系统中所有的日志
  def self.all_articles
    Article.all :order => "created_at"
  end
end
